package cn.edu.nuc.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.controller.page.PageControl;
import cn.edu.nuc.ssm.controller.page.Pager;
import cn.edu.nuc.ssm.controller.page.Pc;
import cn.edu.nuc.ssm.dao.CommentMapper;
import cn.edu.nuc.ssm.domain.Comment;
import cn.edu.nuc.ssm.service.interfaces.ContentService;
@Service
public class ContentServiceImpl implements ContentService {
	   @Autowired
		private CommentMapper mapper;
	    //添加一个评论
		@Override
		public int insert(Comment type) {
			return mapper.insert(type);
		}
		//后台分页显示评论信息
		@Override
		public Pager<Comment> pageList(String titlename, int current) {
			PageControl pc = new PageControl();
			Integer currindex = 1;
			if(current != 0){
				currindex = current;
			}
			pc.setCurrentindex(currindex);
			
			//查询总记录数。(如果带有名字，则查询改名字的总记录数。(模糊查询)
			int count = mapper.count("%"+titlename+"%");
			pc.setRscount(count);
			//初始化分页参数。
			pc = Pc.dealpage(pc);
			//查询具体内容
			List<Comment> type = mapper.selectType("%"+titlename+"%",(pc.getCurrentindex()-1)*pc.getPagesize(),
					pc.getCurrentindex()*pc.getPagesize());
			Pager<Comment> pager = new Pager<Comment>();
			pager.setList(type);
			pager.setPagectrl(pc);
			return pager;
		}
		//通过评论id查询评论信息
		@Override
		public Comment selectByPrimaryKey(Integer ftid) {
			return mapper.selectByPrimaryKey(ftid);
		}
		//更新评论信息
		@Override
		public int updateByPrimaryKey(Comment type) {
			return mapper.updateByPrimaryKeySelective(type);
		}
		//通过主键删除单个评论信息。
		@Override
		public int deleteByPrimaryKey(Integer ftid) {
			return mapper.deleteByPrimaryKey(ftid);
		}

}
